$(function () {
    layui.use('layer',function () {
        var layer = layui.layer;
    });
})

function updatePsw() {
    if(($("#oldPassword").val() == "" && $("#oldPassword").val().length==0)){
        layer.tips("<span>请输入旧密码</span>", "#oldError");
        return ;
    }
    $.post("/user/getUser",null,function (info) {
        var obj = JSON.parse(info);
        $("#id").val(obj.id);
        if($("#oldPassword").val() == obj.psw){
            update()
        }else {
            layer.tips("<span>旧密码错误</span>", "#oldError");
            return ;
        }
    })
}

function update() {
    if(($("#password").val() == "" && $("#password").val().length==0)){
        layer.tips("<span>请输入新密码</span>", "#newError");
        return ;
    }
    if(($("#repassword").val() == "" && $("#repassword").val().length==0)){
        layer.tips("<span>请确认新密码</span>", "#reError");
        return ;
    }
    if($("#password").val() != $("#repassword").val()){
        layer.tips("<span>两次密码不一致</span>", "#reError");
        return;
    }
    $.post("/user/updatePwd","id="+$("#id").val()+"&newPwd="+$("#repassword").val(),function (info) {
        if(info == "ok"){
            top.location.href="/html/login/login.html";
        }
    })
}